import os
import pandas as pd

def process_file(file):
    fo = open(file, 'r')
    res = {}
    for line in fo.readlines():
        ls = line.split(',')
        for i in ls:
            if len(i) < 3: # empty
                if 'GStencil/s' not in res:
                    res['GStencil/s'] = []
                res['GStencil/s'].append(-1)
                continue

            i = i.strip().split(' = ')
            if i[0] not in res:
                res[i[0]] = []
            if 'gstencil' in i[0].lower():
                if 'inf' in i[1] or float(i[1]) > 1000:
                    res[i[0]].append(-1)
                else:
                    res[i[0]].append(float(i[1]))
            else:
                res[i[0]].append(int(i[1]))

    df = pd.DataFrame(res)
    df.to_csv(f'{file}.csv', index=False)

for file in os.listdir():
    if '.log' in file and 'wrong' not in file and '.csv' not in file:
        process_file(file)